package com.ikas.ai.xss;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * XSS过滤
 * @author dbh
 */
public class XssFilter implements Filter {

	/**
	 * Inner Server invoke Flag
	 */
	private static final String INNER = "inner-invoke";

	@Override
	public void init(FilterConfig config) throws ServletException {
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
		// 内部调用需要过滤该过滤器
		if (((HttpServletRequest) request).getHeader(INNER) != null) {
			chain.doFilter(request, response);
			return;
		}
		XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request);
		chain.doFilter(xssRequest, response);
	}

	@Override
	public void destroy() {
	}

}